%%%% Solution Algorithm for the Representative-Agent Equivalent for the Aiyagari (1994,QJE)                  
function F=steady(y,alpha,beta,delta,gamma,varphi,zbar)
% Assignment of Endogenous Variables as:
% y(1) Capital (k)
% y(2) Labor (h)
% y(3) Consumption (c)
% y(4) Wage (w)
% y(5) Real Interest Rate (r)

k=y(1);
h=y(2);
c=y(3);
w=y(4);
r=y(5);

l=zbar*h; %effective labor (l)

gdp=(k^alpha)*(l^(1-alpha));

F(1)=1-beta*(1+r);                      % Consumption-Investment Optimality Condition (i.e. Euler Equation)
F(2)=(c^(-gamma))*w*zbar-h^(1/varphi);       % Consumption-Leisure Optimality Condition
F(3)=gdp-c-delta*k;                     % Aggregate Budget Constraint
F(4)= w-(1-alpha)*((k/l)^alpha);        % Competitive Wage (=MPL)
F(5)= r- (alpha*(l/k)^(1-alpha)-delta); % Competitive Real Interest Rate (=MPK)
